﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeBox.FB.ViewModels;
namespace CodeBox.FB.DataAccess
{
    public class PlayerDataAccess
    {
        OritiaDataContext dbContext;
        public IEnumerable<PlayerScoreViewModel> GetPlayerScore(int crewID, int seasonID)
        {
            dbContext = new OritiaDataContext();
            var playerScore = from pts in dbContext.PlayerTeamSeasons
                              join p in dbContext.Players on pts.PlayerId equals p.ID
                              join c in dbContext.Crews on p.CrewId equals c.ID
                              join f in dbContext.Fixtures on pts.Fixture.Id equals f.Id
                              join t1 in dbContext.Teams on f.TeamID1 equals t1.ID
                              join t2 in dbContext.Teams on f.TeamID2 equals t2.ID
                              where p.CrewId == crewID && pts.Season.ID == 1
                              select new PlayerScoreViewModel
                                {
                                    Run1 = (int)(pts.Run1 ?? 0),
                                    Run2 = (int)(pts.Run2 ?? 0),
                                    Run3 = (int)(pts.Run3 ?? 0),
                                    Run4 = (int)(pts.Run4 ?? 0),
                                    Run6 = (int)(pts.Run6 ?? 0),
                                    BallsBowled = (int)(pts.BallsBowled ?? 0),
                                    RunsGiven = (int)(pts.RunsGiven ?? 0),
                                    Wickets = (int)(pts.Wickets ?? 0),
                                    Catches = (int)(pts.Catches ?? 0),
                                    Dot = (int)(pts.Dot ?? 0),
                                    NoBall = (int)(pts.NoBall ?? 0),
                                    Match = (t1.TeamName + " v/s " + t2.TeamName)
                                };
            return playerScore.AsEnumerable();

        }
    }
}




